<?php

namespace core\lib\drive\log;

use core\lib\config;

class file {
    public $path;

    public function __construct() {
        $option = config::get('OPTION', 'log');
        $this->path = $option['PATH'];
    }

    public function log($message, $file = 'log') {
        /**
         * 1. 确定文件是否存在
         *      新建目录
         * 2. 写入日志
         */
        if (!is_dir($this->path)) {
            mkdir($this->path, '0777', true);
        }
        $message = date('Y-m-d H:i:s') . PHP_EOL . json_encode($message, JSON_UNESCAPED_UNICODE) . PHP_EOL;
        file_put_contents($this->path . '/' . $file . '.php', $message, FILE_APPEND);
    }
}